from typing import List
class Solution:
    def isSatisfied(self, nums: List[int], l: int, r: int, threshold: int) -> bool:
        if nums[l] % 2 != 0:
            return False
        for i in range(l, r + 1):
            if nums[i] > threshold or (i < r and nums[i] % 2 == nums[i + 1] % 2):
                return False
        return True

    def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:
        res = 0
        for l in range(0, len(nums)):
            for r in range(l, len(nums)):
                if self.isSatisfied(nums, l, r, threshold):
                    res = max(res, r - l + 1)
        return res
